<!-- 资讯管理 -->
<template>
  <div class="tenantCertification">
    <Tree @searchManagement="searchManagement" />
    <div class="table-box">
      <div class="table-operator">
        <a-button type="primary" @click="handleSave">保存</a-button>
      </div>
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      >
        <!-- 序号 -->
        <span slot="serial" slot-scope="text, record, index">
          {{ (pagination.current - 1) * pagination.pageSize + parseInt(index) + 1 }}
        </span>
        <!-- 封面图 -->
        <span slot="coverUrl" slot-scope="text">
          <img style="width: 80px; height: 60px; cursor: pointer" :src="text" alt="" />
        </span>
        <!-- 操作按钮 -->
        <!-- <span slot="action" slot-scope="text, record">
                    <template>
                        <a @click="handleEdit(record)">编辑</a>
                        <a-divider type="vertical" />
                        <a @click="handleCopy(record)">复制</a>
                        <a-divider type="vertical" />
                        <a @click="handleDel([record.id])">删除</a>
                    </template>
                </span> -->
      </s-table>
    </div>
  </div>
</template>

<script>
import { STable } from '@/components'
import { consultGetList, consultDel, getModuleList } from '@/api/content/management'
import { configWebsiteInfoDynamic, saveConfigWebsiteInfoDynamic } from '@/api/web/web'
import Tree from './components/TreeType'
export default {
  components: {
    STable,
    Tree,
  },
  data() {
    return {
      pagination: {
        current: 1,
        pageSize: 10,
      },
      enabled: 1,
      visible: false,
      queryParam: {
        title: '',
        module: null,
        moduleSub: null,
      },
      moduleList: [], // 一级导航
      moduleSubList: [], // 二级导航
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      columns: [
        {
          title: '标题',
          dataIndex: 'title',
          ellipsis: true,
        },
        {
          title: '封面',
          dataIndex: 'coverUrl',
          scopedSlots: { customRender: 'coverUrl' },
        },
        {
          title: '发布时间',
          dataIndex: 'pubdate',
          width: '200px',
          ellipsis: true,
        },
        // {
        //     title: "操作",
        //     width: "150px",
        //     dataIndex: "action",
        //     fixed: "right",
        //     scopedSlots: { customRender: "action" },
        // },
      ],
      range: null,
      pageNum: 1,
      moduleValue: [],
      // moduleOptions: [],
      // pageSize: 10,
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        var params = {
          current: parameter.pageNum,
          size: parameter.pageSize,
        }
        this.listLoading = true
        return consultGetList(Object.assign(params, this.queryParam))
          .then((res) => {
            this.listLoading = false
            this.pageNum = parameter.pageNum
            this.pageSize = parameter.pageSize
            return res
          })
          .catch((err) => {
            this.listLoading = false
            this.$message.error(err.msg)
          })
      },
      selectedRowKeys: [],
    }
  },
  watch: {
    moduleValue(val) {
      if (val[0]) this.queryParam.module = val[0]
      if (val[1]) this.queryParam.moduleSub = val[1]
      if (val.length === 0) {
        this.queryParam.module = null
        this.queryParam.moduleSub = null
      }
    },
  },
  created() {
    this.getConfigWebsiteInfoDynamic()
  },
  methods: {
    searchManagement(params) {
      this.queryParam = {
        ...this.queryParam,
        ...params,
      }
      this.$refs.table.refresh(true)
    },
    async getConfigWebsiteInfoDynamic() {
      let res = await configWebsiteInfoDynamic()
      this.selectedRowKeys = res.data.infoIdList || []
    },
    onSelectChange(rowKeys, rows) {
      this.selectedRowKeys = rowKeys
    },
    async handleSave() {
      let { code, msg } = await saveConfigWebsiteInfoDynamic({
        infoIdList: this.selectedRowKeys,
        showType: 0,
      })
      this.$message[code === 0 ? 'success' : 'error'](msg)
      if (code === 0) {
        this.getConfigWebsiteInfoDynamic()
      }
    },
  },
}
</script>
<style scoped lang="less">
.tenantCertification {
  min-height: calc(100vh - 200px);
  background: #ffffff;
  padding: 0 24px;
  box-sizing: border-box;
  border-radius: 10px;
  display: flex;
}

.table-box {
  box-sizing: border-box;
  background: #ffffff;
  box-shadow: 0px 0px 0px #000000;
  border-radius: 10px;
  padding: 15px;
  margin-bottom: 20px;
  box-sizing: border-box;
}
</style>
